#include "nosal/log/logging.h"
#include "nosal/log/internal/log_manager.h"
#include <iostream>
#include <mutex>

namespace netaos {
namespace nosal {
namespace log {

namespace {
std::once_flag gCheckLoggingInit;
internal::LogManager& logManager()
{
    static auto logManager = new internal::LogManager();
    return *logManager;
}
}  // namespace

void InitLogging(std::string application_id,
		std::string description,
		LogLevel loglevel,
		LogMode logmode,
		std::string directory_path) noexcept
{
    std::call_once(gCheckLoggingInit, [&]() {
        logManager().Initialize(application_id,
			description,
			loglevel,
			logmode,
			directory_path);
    });
}

Logger& CreateLogger(std::string context_id,
		std::string description,
		LogLevel default_loglevel) noexcept
{
    std::call_once(gCheckLoggingInit, []() {
        std::cerr << "netaos::nosal::log::Initialization missing" << std::endl;
    });

    return logManager().CreateLogContext(context_id, description, default_loglevel);
}

}  // namespace log
}  // namespace nosal
}  // namespace netaos

